import { createRouter, createWebHistory } from 'vue-router';
import Home from '../views/Home.vue';
import Login from '../components/Login.vue';
import Register from '../components/Register.vue';
import Destination from '../views/Destination.vue';
import DestinationDetail from '../views/DestinationDetail.vue';
import Guide from '../views/Guide.vue';
import Hotel from '../views/Hotel.vue';
import Flight from '../views/Flight.vue';
import UserCenter from '../views/UserCenter.vue';

const routes = [
  {
    path: '/',
    name: 'Home',
    component: Home
  },
  {
    path: '/login',
    name: 'Login',
    component: Login
  },
  {
    path: '/register',
    name: 'Register',
    component: Register
  },
  {
    path: '/destination',
    name: 'Destination',
    component: Destination
  },
  {
    path: '/destination/:id',
    name: 'DestinationDetail',
    component: DestinationDetail
  },
  {
    path: '/guide',
    name: 'Guide',
    component: Guide
  },
  {
    path: '/hotel',
    name: 'Hotel',
    component: Hotel
  },
  {
    path: '/flight',
    name: 'Flight',
    component: Flight
  },
  {
    path: '/user',
    name: 'UserCenter',
    component: UserCenter,
    meta: { requiresAuth: true }
  }
];

const router = createRouter({
  history: createWebHistory(),
  routes
});

// 简单的路由守卫，检查是否需要登录
router.beforeEach((to, from, next) => {
  // 这里应该检查用户是否已登录
  const isLoggedIn = localStorage.getItem('isLoggedIn') === 'true';
  
  if (to.meta.requiresAuth && !isLoggedIn) {
    next({ name: 'Login', query: { redirect: to.fullPath } });
  } else {
    next();
  }
});

export default router; 